﻿@model Matrix.MaKaYunShang.Model.SysPayDiscountConfig
@{
    ViewBag.Title = "立减规则设置";
    ViewBag.PathToBtn = "/SysConfig/SysPayDiscountConfigList";
    ViewBag.TextBtn = "返回立减规则列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                立减规则编辑
            </div>
            <div class="panel-body">
                <div class="row">
                    @using (Html.BeginForm("SysPayDiscountConfig", "SysConfig", FormMethod.Post, new { id = "frmCreate", enctype = "multipart/form-data" }))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)

                        <div class="col-lg-12">
                            <fieldset>

                                <div class="form-group col-md-6">
                                    <label>立减金额区间最小值</label>
                                    @Html.TextBoxFor(model => model.MinPayDiscount, new { @class = "form-control", placeholder = "立减金额区间最小值" })
                                </div>
                                <div class="form-group col-md-6">
                                    <label>立减金额区间最大值</label>
                                    @Html.TextBoxFor(model => model.MaxPayDiscount, new { @class = "form-control", placeholder = "立减金额区间最大值" })
                                </div>
                                <div class="form-group col-md-6">
                                    <label>权重</label>
                                    @Html.TextBoxFor(model => model.DiscountProbability, new { @class = "form-control", placeholder = "权重" })
                                </div>
                                <div class="col-md-12">
                                    <button type="button" class="btn btn-primary" id="btnSave">保存设置</button>
                                </div>
                            </fieldset>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

@section javascript{
    <script type="text/javascript">
        $(function () {
            $("#frmCreate").validate({
                rules: {
                    MinPayDiscount: { required: true, min: 0.1, number: true },
                    MaxPayDiscount: { required: true, min: 0.1, number: true },
                    DiscountProbability: { required: true, min: 0.1, number: true }
                },
                messages: {
                    MinPayDiscount: { required: "请填写立减金额区间最小值" },
                    MaxPayDiscount: { required: "请填写立减金额区间最大值" },
                    DiscountProbability: { required: "请填写权重值" }
                }
            });

            $("#btnSave").click(function () {
                if ($("#frmCreate").valid()) {

                    if (parseFloat($("#MaxPayDiscount").val()) <= parseFloat($("#MinPayDiscount").val())) {
                        alertify.error("立减金额最大值不可小于立减金额最小值");
                        $("#MaxRedEnvolope").focus();
                        return false;
                    }
                    $.ajax({
                        type: 'post',
                        url: '@Url.Action("SysPayDiscountConfig")',
                        data: $("#frmCreate").serialize(),
                        success: function (data) {
                            if (data.Status) {
                                alertify.success("保存成功");
                                location.href = "/SysConfig/SysPayDiscountConfigList";
                                     } else {
                                alertify.error(data.Message);
                            }
                        },
                        error: function () {
                            alertify.error("保存失败，请重试！");
                        }
                    });
                }
            });

       
        });

    </script>
}